package com.jumi.microservice.mapper;

import com.jumi.microservice.entity.JmExtraDiscountChangeLog;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;

/**
 * <p>
 * 额外折扣变更表 Mapper 接口
 * </p>
 *
 * @author 要挑客户管理团队
 * @since 2020-10-15
 */
public interface JmExtraDiscountChangeLogMapper extends BaseMapper<JmExtraDiscountChangeLog> {

    @Select("SELECT SUM(t.discount)as used_discount\n" +
            "FROM\n" +
            "(\n" +
            "SELECT l.uid,l.discount FROM `jm_extra_discount_change_log` l\n" +
            "WHERE l.uid=#{uid} \n" +
            "AND l.discount_type in ('reduce','refund_back')\n" +
            ")t")
    BigDecimal getUsedDiscountByUid(Integer uid);
}
